commit 810990a7465f31ee5ff5e29ebea1fb783e5ed502
Author: wm4 <wm4@nowhere>
Date:   Tue Sep 19 18:59:01 2017 +0200

mp_image: always copy color attributes on hw download

It was noticed that -copy hwdec modes typically dropped the
chroma_location field. This happened because the attributes on hw
download are copied with mp_image_copy_attributes(), which tries to copy
these parameters only if src and dst were both YUV (in an attempt to
copy parameters only if it makes sense).

But hardware formats did not have the YUV flag set (anymore?), and code
shouldn't attempt to check the flag in this way anyway. Drop the check,
and always copy the whole color metadata struct. There is a call to
mp_image_params_guess_csp() below, which tries to unset nonsense
metadata if it was copied from a YUV format to RGB. This function would
also do the right thing for hw formats (although for the cited bug only
the software case matters).

Fixes #4804.

diff --git a/video/mp_image.c b/video/mp_image.c
index 7180e2be5..5aa564775 100644
--- a/video/mp_image.c
+++ b/video/mp_image.c
@@ -525,15 +525,8 @@ void mp_image_copy_attributes(struct mp_image *dst, struct mp_image *src)
         dst->params.p_w = src->params.p_w;
         dst->params.p_h = src->params.p_h;
     }
-    dst->params.color.primaries = src->params.color.primaries;
-    dst->params.color.gamma = src->params.color.gamma;
-    dst->params.color.sig_peak = src->params.color.sig_peak;
-    dst->params.color.light = src->params.color.light;
-    if ((dst->fmt.flags & MP_IMGFLAG_YUV) == (src->fmt.flags & MP_IMGFLAG_YUV)) {
-        dst->params.color.space = src->params.color.space;
-        dst->params.color.levels = src->params.color.levels;
-        dst->params.chroma_location = src->params.chroma_location;
-    }
+    dst->params.color = src->params.color;
+    dst->params.chroma_location = src->params.chroma_location;
     dst->params.spherical = src->params.spherical;
     mp_image_params_guess_csp(&dst->params); // ensure colorspace consistency
     if ((dst->fmt.flags & MP_IMGFLAG_PAL) && (src->fmt.flags & MP_IMGFLAG_PAL)) {
